#include "Attributes.h"


/************************************************
/*				Static
/************************************************/

    /************************************************
    /*				Properties
    /************************************************/

    std::vector<GLuint> Attributes::m_Index;

    /************************************************
    /*				Methods
    /************************************************/

    void Attributes::BindAttribute()
    {
        glEnableVertexAttribArray(m_Index[0]);
        glEnableVertexAttribArray(m_Index[1]);
        glEnableVertexAttribArray(m_Index[2]);
        glEnableVertexAttribArray(m_Index[3]);

        GLuint offset1  =   0;
        GLuint offset2  =   4*sizeof(float);
        GLuint offset3  =   4*2*sizeof(float);
        GLuint offset4  =   4*3*sizeof(float);

        glVertexAttribPointer(m_Index[0],4,GL_FLOAT, GL_FALSE, ((4*4))*sizeof(float), (void*)+offset1);
        glVertexAttribPointer(m_Index[1],4,GL_FLOAT, GL_FALSE, ((4*4))*sizeof(float), (void*)+offset2);
        glVertexAttribPointer(m_Index[2],4,GL_FLOAT, GL_FALSE, ((4*4))*sizeof(float), (void*)+offset3);
        glVertexAttribPointer(m_Index[3],4,GL_FLOAT, GL_FALSE, ((4*4))*sizeof(float), (void*)+offset4);
    }

    void Attributes::UnbindAttributes()
    {
        glDisableVertexAttribArray(m_Index[0]);
        glDisableVertexAttribArray(m_Index[1]);
        glDisableVertexAttribArray(m_Index[2]);
        glDisableVertexAttribArray(m_Index[3]);
    }

/************************************************
/*				Members
/************************************************/


    /************************************************
    /*				Constructors
    /************************************************/

    Attributes::Attributes()
    {
        Init(new vec4(), new vec4(), new vec4(), new vec4());
    }

    Attributes::Attributes(vec4 *position)
    {
        Init(position, new vec4(), new vec4(), new vec4());
    }

    Attributes::Attributes(vec4 *position, vec4 *color)
    {
        Init(position, color, new vec4(), new vec4());
    }

    Attributes::Attributes(vec4 *position, vec4 *color, vec4 *normal)
    {
        Init(position, color, normal, new vec4());
    }

    Attributes::Attributes(vec4 *position, vec4 *color, vec4 *normal, vec4 *texcoord0)
    {
        Init(position, color, normal, texcoord0);
    }

    void Attributes::Init(vec4 *position, vec4 *color, vec4 *normal, vec4 *texCoord)
    {
        m_Position=position; m_Color=color; m_Normal=normal; m_Texcoord0=texCoord;
        StoreReference();
    }

    void Attributes::StoreReference()
    {
        m_Attributes.push_back(m_Position);
        m_Attributes.push_back(m_Color);
        m_Attributes.push_back(m_Normal);
        m_Attributes.push_back(m_Texcoord0);
    }
